<?php session_start();?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<script LANGUAGE="javascript">
function redirectPageComplete()
{	
	alert("บันทึก email สำเร็จ");
	location = "../../emails.php";
}

function redirectPageIncomplete()
{
	alert("เกิดข้อผิดพลาดในการเพิ่มข้อมูล");
	location = "../../emails.php";
}

function redirectPageIsnull()
{
	alert("ข้อมูลบางส่วนยังเป็น่ค่าว่าง กรุณาลงใหม่อีกครั้ง");
	location = "../../emails.php";
	
}
<?php
include '../../../inc/reuse/dbconfig.php';

$id = $_POST['email_id'];
$email_owner = $_POST['email_owner'];
$email_name = $_POST['email_name'];
$modifier = $_SESSION['uid'];
$modified_datetime = date("YmdHis"); //เก็บวันเดือนปีและเวลาด้วย function date
if(isset($email_owner,$email_name) && $id != ""){
	$sql = "UPDATE emails
			SET emails_owner_name = '$email_owner',
			emails_description = '$email_name',			
			modified_master_id = '$modifier',
			modified_date_time = '$modified_datetime' 
			WHERE emails_id= $id";
	if(mysql_query($sql)){
		echo "redirectPageComplete();";
	}else{
		echo "redirectPageIncomplete();";
	}
}
else
{
	$sql = "INSERT INTO emails (emails_id,emails_owner_name,emails_description,inserted_master_id,inserted_date_time,modified_master_id,modified_date_time)
	VALUES (null,'$email_owner', '$email_name', '$modifier', '$modified_datetime', '$modifier', '$modified_datetime')";
	if(mysql_query($sql)){
		echo "redirectPageComplete();";
	}else{
		echo "redirectPageIncomplete();";
	}	
}
mysql_close();
?>
</script>
</body>
</html>
